package TP2;

/**
 * Camion
 * */
public class Camion extends Thread {


	
	/**
	 * liste
	 * */
	private Site[] sites;
	private static int stockVelos;

	public Camion(Site[] sites) {
		this.sites = sites;
	}

	public void verifierSite(int i) {
		if (sites[i].getNbVelos() > sites[i].borneSup) {
			sites[i].retirer();
		} else if (sites[i].getNbVelos() < sites[i].borneInf) {
			sites[i].ajouter();
		}
		notifyAll();
	}

	public static int getStockVelos() {
		return stockVelos;
	}

	public static void setStockVelos(int nb) {
		stockVelos = nb;
	}

	public void run() {
		while (Client.getNbClients() > 0) {
			for (int i = 0; (i % sites.length) < sites.length; i++) {
				verifierSite(i);
				try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
				}
			}
		}
	}
}
